package com.xiangge.test;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Demo8 {
    public static void main(String[] args) {
        int[] arr = new int[7];
        for (int i = 0; i < 6; i++) {
            while (true) {
                int temp = new Random().nextInt(33-1+1)+1;
                boolean flag = true;
                for (int num : arr) {
                    if (temp==num){
                        flag=false;
                        break;
                    }
                }
                if (flag){
                    arr[i]=temp;
                    break;
                }

            }

        }
        arr[6] = new Random().nextInt(16-1+1)+1;
        System.out.println("中奖号码为"+Arrays.toString(arr));


        getZhongjiang(arr);

    }

    public static void getZhongjiang(int[] arr) {
        int[] inputNum = getInputNum();

        int red = 0;
        int blue = 0;
        for (int i = 0; i <= 5; i++) {
            if (arr[i]==inputNum[i]){
                red++;
            }
        }
//        System.out.println("red = " + red);
        if (inputNum[6]== arr[6]){
            blue = 1;
            switch (red){
                case 0:
                case 1:
                case 2:
                case 3:
                    System.out.println("您猜中了"+blue+"个蓝球，"
                            +red+ "个红球奖金5元");
                    break;
                case 4:
                    System.out.println("您猜中了"+blue+"个蓝球，"
                            +red+ "个红球奖金200元");
                    break;
                case 5:
                    System.out.println("您猜中了"+blue+"个蓝球，"
                            +red+ "个红球奖金3000元");
                    break;
                case 6:
                    System.out.println("您猜中了"+blue+"个蓝球，"
                            +red+ "个红球奖金1000万元");
                    break;

            }

        }else {
            switch (red){
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    System.out.println("您没有猜中蓝球，谢谢惠顾");
                    break;
                case 6:
                    System.out.println("您猜中了"+red+ "个红球奖金500万元");
                    break;

            }
        }
    }


    public static int[] getInputNum(){
        System.out.println("请输入一组7位号码");
        int[] arr = new int[7];
        Scanner input = new Scanner(System.in);


        for (int i = 0; i < 6; i++) {

            System.out.print("请输入第"+(i+1)+"位号码:");
            int x = input.nextInt();
            if (x<1||x>33){
                System.err.println("请输入范围内的数");
                break;
            }
            arr[i] = x;
        }
        while (true) {
            System.out.print("请输入第"+7+"位号码:");
            int x = input.nextInt();
            if (x<1||x>16){
                System.err.println("请输入范围内的数");
            }else {
                arr[6] = x;
                break;
            }
        }
        return arr;
    }
}
